import java.util.ArrayList;
import java.util.List;

class Solution11 {
    public List<String> ret;
    public List<String> binaryTreePaths(TreeNode root) {
        StringBuffer path = new StringBuffer();
        ret = new ArrayList<>();
        difs(root,path);
        return ret;
    }

    public void difs(TreeNode root,StringBuffer _path) {
        StringBuffer path = new StringBuffer(_path);//恢复现场
        if(root.left == null && root.right == null) {
            path.append(root.val);
            ret.add(path.toString());
            return;
        }
        path.append(root.val);
        path.append("->");
        if(root.left != null) difs(root.left,path);
        if(root.right != null) difs(root.right,path);
    }
}